import { get, post, put, del } from '@/utils/http'
import { BaseResponse, LoginResponse, GetUsersResponse, GetUserProfileResponse } from '@/api/modules/userModels'

const apiList = {
    login: "/login",
    get_users: "/users/",
    add_user: "/users/",
    update_user: (id: string | number) => `/users/${id}`,
    delete_user: (id: string | number) => `/users/${id}`,
    update_user_status: (id: string | number) => `/users/${id}/status`,
    change_password: "/change/password",
    reset_password: (id: string | number) => `/users/${id}/reset/password`,
    get_user_profile: "/users/profile",
    edit_user_profile: "/users/profile",
}

export const loginAPI = async (data: object): Promise<LoginResponse> => {
    return await post<LoginResponse>(apiList.login, data);
}

export const getUsersAPI = async (params: object): Promise<GetUsersResponse> => {
    return await get<GetUsersResponse>(apiList.get_users, params)
}

export const addUserAPI = async (data: object): Promise<BaseResponse> => {
    return await post<BaseResponse>(apiList.add_user, data)
}

export const updateUserAPI = async (id: number, data: object): Promise<BaseResponse> => {
    return await put<BaseResponse>(apiList.update_user(id), data)
}

export const deleteUserAPI = async (id: number): Promise<BaseResponse> => {
    return await del<BaseResponse>(apiList.delete_user(id))
}

export const updateUserStatusAPI = async (id: number, data: object): Promise<BaseResponse> => {
    return await put<BaseResponse>(apiList.update_user_status(id), data)
}

export const changePasswordAPI = async (data: object): Promise<BaseResponse> => {
    return await post<BaseResponse>(apiList.change_password, data)
}

export const resetPasswordAPI = async (id: number, data: object): Promise<BaseResponse> => {
    return await post<BaseResponse>(apiList.reset_password(id), data)
}

export const getUserProfile = async (params: object): Promise<GetUserProfileResponse> => {
    return await get<GetUserProfileResponse>(apiList.get_user_profile, params)
}

export const editUserProfile = async (data: object): Promise<BaseResponse> => {
    return await put<BaseResponse>(apiList.edit_user_profile, data)
}